home *** CD-ROM | disk | FTP | other *** search
- @echo off
- ! addPath.bat Batch file to insert a folder in the PATH
- !
- ! addPath fold skip
- !
- ! 'fold' is the folder to be inserted
- ! 'skip' is how many existing folders have to be skipped before inserting
- ! the new folder. If it is missing, the new folder is appended to
- ! the end of the path.
- !
- ! Example:
- ! addPath applied to the initial PATH "first;second;third" will have the
- ! following results:
- ! addPath xxx first;second;third;xxx
- ! addPath xxx 0 xxx;first;second;third
- ! addPath xxx 1 first;xxx;second;third
- ! addPath xxx 2 first;second;xxx;third
- ! addPath xxx 3 first;second;third;xxx
- ! ...
- ! addPath xxx 57 first;second;third;xxx
- !
- ! Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
- !
-
- set addPath_saved_path=%PATH%
-
- ! ensure that the first parameter is there
- set doserr=13
- if "%1 " == " " goto ERR_LBL
-
- ! determine the position
- if "%2 " == " " goto AT_END_LBL
- set addPath_skip=%2
-
- !
- ! scan the existing PATH and skip one folder at a time until you reach
- ! the requested position or until you run out of folders
- !
- set addPath_tail=%PATH%
- set doserr=0
- :SKIP_ONE_LBL
- if %addPath_skip% == 0 goto POS_FOUND_LBL
- if "%addPath_tail%" == %%ADDPATH_TAIL%% goto AT_END_LBL
- sstr addPath_tail ; /R
- if %doserr% == 72 goto AT_END_LBL
- decr addPath_skip
- goto SKIP_ONE_LBL
-
- :AT_END_LBL
- !
- ! append the new folder to the end
- incr path by ";%1"
- goto DONE_LBL
-
- :POS_FOUND_LBL
- !
- ! insert the new folder in the appropriate position
- decr path by "%addPath_tail%"
- incr path by "%1;%addPath_tail%"
- goto DONE_LBL
-
- :ERR_LBL
- show %doserr%
- set path=%addPath_saved_path%
-
- :DONE_LBL
- ! remove the global variables
- set addPath_skip=
- set addPath_tail=
- set addPath_saved_path=
-